package com.yanqu.road.logic.activity.chefduel;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.chefduel.process3.ChefDuel3OpenItem;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.Random;

public class ChefDuel3Config {

    private ActivityInfo activityInfo;

    private int activityId;

    Map<String, ActivityConfig> activityConfigMap;

    private Random random = new Random();

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public Map<String, ActivityConfig> getActivityConfigMap() {
        return activityConfigMap;
    }

    private String CHEFDUEL3_GUESS_WIN_REWARD;
    private String CHEFDUEL3_GUESS_LOSE_REWARD;

    private int CHEFDUEL3_QUIZ_TIME;

    public ChefDuel3Config(ActivityInfo tmpActivityInfo, Map<String, ActivityConfig> tmpActivityConfigMap){
        this.activityInfo = tmpActivityInfo;
        this.activityId = activityInfo.getActivityId();
        this.activityConfigMap = tmpActivityConfigMap;
        //去数据库拿数据

        CHEFDUEL3_GUESS_WIN_REWARD = activityConfigMap.get("CHEFDUEL3_GUESS_WIN_REWARD").getValue();
        CHEFDUEL3_GUESS_LOSE_REWARD = activityConfigMap.get("CHEFDUEL3_GUESS_LOSE_REWARD").getValue();
        CHEFDUEL3_QUIZ_TIME = activityConfigMap.get("CHEFDUEL3_QUIZ_TIME").getIntValue();

    }

    //小当家第三阶段
    public static final String COOKBOY3_SWITCH	 =  "1"; //是否开启凭证参与
    public static final String COOKBOY3_CERTIFICATE_CONSUME	="120467=1";//参与活动需要消耗的凭证道具
    public static final String COOKBOY3_EXCHANGE_ITEM_ID	="101969";//兑换商店积分道具ID
    public static final String COOKBOY3_BANQUET_OPEN_CONFIG	="120468=1;50;60;20|120469=1;100;120;25|120470=1;150;180;30";//开宴道具消耗、试吃人数、持续时间(分)、赴宴人赴宴给开宴人增加的积分
    public static final String COOKBOY3_JOIN_BANQUET_REWARD	="121068=1|121069=1|121070=1";//赴宴奖励宝箱ID，区分不同宴会
    public static final String COOKBOY3_JOIN_BANQUET_SCORE	="100";//赴宴试吃增加的宴会积分
    public static final String COOKBOY3_SERVE_FOOD_DAY_START	="10";//每天开始比赛时间小时
    public static final String COOKBOY3_SERVE_FOOD_DAY_END	="22";//每天结束比赛时间小时
    public static final String COOKBOY3_WORSHIP_REWARDS	="101000=200";//膜拜奖励列表
    public static final String COOKBOY3_ROBOT_ADD = "1000";//机器人填补座位加成积分千分比

    public boolean isChefDuel3Able(){
        String strConfig = COOKBOY3_SWITCH;
        if(activityConfigMap.containsKey("COOKBOY3_SWITCH")){
            strConfig = activityConfigMap.get("COOKBOY3_SWITCH").getValue();
        }
        return Integer.valueOf(strConfig) == 0;
    }

    public ChefDuel3OpenItem getChefDuel3OpenItem(int itemId){
        String strConfig = COOKBOY3_BANQUET_OPEN_CONFIG;
        if(activityConfigMap.containsKey("COOKBOY3_BANQUET_OPEN_CONFIG")){
            strConfig = activityConfigMap.get("COOKBOY3_BANQUET_OPEN_CONFIG").getValue();
        }
        List<String> infoList = StringUtils.stringToStringList(strConfig,"\\|");
        int i = 1;
        for(String info : infoList){
            List<String> itemList = StringUtils.stringToStringList(info,";");
            String consume = itemList.get(0);
            int itemConfigId = StringUtils.stringToIntegerList(consume,"=").get(0);
            if(itemConfigId == itemId){
                ChefDuel3OpenItem config = new ChefDuel3OpenItem();
                config.setItemId(itemId);
                config.setEatNum(Integer.valueOf(itemList.get(1)));
                config.setMinute(Integer.valueOf(itemList.get(2)));
                config.setIntegral(Long.valueOf(itemList.get(3)));
                config.setConsume(consume);
                config.setPos(i);
                return config;
            }
            i++;
        }
        return null;
    }

    public String getChefDuel3OpenJoinerReward(int itemId){
        ChefDuel3OpenItem cookBoy3OpenItem = getChefDuel3OpenItem(itemId);
        if(cookBoy3OpenItem == null){
            return "";
        }
        String strConfig = COOKBOY3_JOIN_BANQUET_REWARD;
        if(activityConfigMap.containsKey("COOKBOY3_JOIN_BANQUET_REWARD")){
            strConfig = activityConfigMap.get("COOKBOY3_JOIN_BANQUET_REWARD").getValue();
        }
        List<String> infoList = StringUtils.stringToStringList(strConfig,"\\|");
        return infoList.get(cookBoy3OpenItem.getPos()-1);
    }

    public int getChefDuel3IntegralItemId(){
        if(activityConfigMap.containsKey("COOKBOY3_EXCHANGE_ITEM_ID")){
            return Integer.valueOf(activityConfigMap.get("COOKBOY3_EXCHANGE_ITEM_ID").getValue());
        }
        return Integer.valueOf(COOKBOY3_EXCHANGE_ITEM_ID);
    }

    public String getWorship3Reward(){
        if(activityConfigMap.containsKey("COOKBOY3_WORSHIP_REWARDS")){
            return activityConfigMap.get("COOKBOY3_WORSHIP_REWARDS").getValue();
        }
        return COOKBOY3_WORSHIP_REWARDS;
    }

    public int getServeBanquetStartHour(){
        if(activityConfigMap.containsKey("COOKBOY3_SERVE_FOOD_DAY_START")){
            return Integer.valueOf(activityConfigMap.get("COOKBOY3_SERVE_FOOD_DAY_START").getValue());
        }
        return Integer.valueOf(COOKBOY3_SERVE_FOOD_DAY_START);
    }

    public int getServeBanquetEndHour(){
        if(activityConfigMap.containsKey("COOKBOY3_SERVE_FOOD_DAY_END")){
            return Integer.valueOf(activityConfigMap.get("COOKBOY3_SERVE_FOOD_DAY_END").getValue());
        }
        return Integer.valueOf(COOKBOY3_SERVE_FOOD_DAY_END);
    }

    public String getCHEFDUEL3_GUESS_WIN_REWARD() {
        return CHEFDUEL3_GUESS_WIN_REWARD;
    }

    public String getCHEFDUEL3_GUESS_LOSE_REWARD() {
        return CHEFDUEL3_GUESS_LOSE_REWARD;
    }

    public int getCHEFDUEL3_QUIZ_TIME() {
        return CHEFDUEL3_QUIZ_TIME;
    }
}
